package com.github.m6d21.sso.dao.role.dao.impl;

import com.github.m6d21.sso.dao.role.dao.IUnionRoleDao;
import com.github.m6d21.sso.dao.role.mapper.UnionRoleMapper;
import com.github.m6d21.sso.model.role.dto.RolePermissionDTO;
import com.github.m6d21.sso.model.role.qo.RolePermissionQO;
import com.github.m6d21.sso.model.role.vo.UnionRole;
import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Repository;

/**
 *<p>
 *
 *</p>
 *
 * @author liuyang
 * @date 2019/1/4 Fri 17:00:00
 * @since 1.0.0
 */
@Repository("unionRoleDao")
public class UnionRoleDaoImpl implements IUnionRoleDao {

    @Resource
    private UnionRoleMapper unionRoleMapper;

    @Override
    public List<UnionRole> unionQuery(RolePermissionQO rolePermissionQO) {
        if (rolePermissionQO == null) {
            rolePermissionQO = new RolePermissionQO();
        }
        return unionRoleMapper.unionQuery(rolePermissionQO);
    }

    @Override
    public Boolean insertRolePermissionRelation(RolePermissionDTO rolePermissionDTO) {
        if (rolePermissionDTO == null) {
            return false;
        }
        int rows = unionRoleMapper.insertRolePermissionRelation(rolePermissionDTO);
        return rows == 1;
    }

    @Override
    public int insertBatchRolePermissionRelation(List<RolePermissionDTO> rolePermissionDTOList) {
        if (CollectionUtils.isEmpty(rolePermissionDTOList)) {
            return 0;
        }
        return unionRoleMapper.insertBatchRolePermissionRelation(rolePermissionDTOList);
    }

    @Override
    public int deleteBatchRolePermissionRelation(Integer roleId, List<Integer> permissionIds) {
        if(roleId==null){
            return 0;
        }
        return unionRoleMapper.deleteBatchRolePermissionRelation(roleId, permissionIds);
    }
}
